package com.xz.stu.server.controller;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import com.xz.stu.server.mapper.CourseMapper;
import com.xz.stu.server.vo.course.*;
import com.xz.stu.server.service.CourseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "课程管理")
@RestController
@RequestMapping("admin-api/school/course")
public class CourseController {

    @Resource
    private CourseService courseService;

    @PostMapping("/create")
    @Operation(summary = "创建课程")
    public CommonResult<Long> createCourse(@Valid @RequestBody CourseCreateReqVO createReqVO) {
        return success(courseService.createCourse(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新课程")
    public CommonResult<Boolean> updateCourse(@Valid @RequestBody CourseUpdateReqVO updateReqVO) {
        courseService.updateCourse(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete/{courseId}")
    @Operation(summary = "删除课程")
    public CommonResult<Boolean> deleteCourse(@PathVariable("courseId") List<Long> courseId) {
        courseService.deleteCourse(courseId);
        return success(true);
    }

    @GetMapping("/get/{courseId}")
    @Operation(summary = "获得课程")
    public CommonResult<CourseRespVO> getCourse(@PathVariable("courseId") Long courseId) {
        return success(courseService.getCourse(courseId));
    }

    @GetMapping("/list")
    @Operation(summary = "获得课程列表")
    public CommonResult<List<CourseRespVO>> getCourseList(@Valid CourseListReqVO listReqVO) {
        return success(courseService.getCourseList(listReqVO));
    }

    @GetMapping("/listPage")
    @Operation(summary = "获得课程列表-分页")
    public CommonResult<PageResult<CourseRespVO>> getCourseListPage(@Valid CourseListPageReqVO listReqVO) {
        return success(courseService.getCourseListPage(listReqVO));
    }

    /**
     * 学生课表查询
     */
    @GetMapping("/student/schedule")
    @Operation(summary = "学生课表查询")
    public CommonResult<List<ScheduleRespVO>> getCourseListSchedule(@RequestParam ("week") Integer week,@RequestParam ("termId") Long termId) {
        return success(courseService.getCourseListSchedule(week,termId));
    }

}
